From cbe40f5f46d8358ec944b00037d73482d2d6b4a2 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Fri, 16 Mar 2018 04:29:42 +0100 Subject: [PATCH] image: Remove gtk_image_set_texture() gtk_image_get_paintable() is a perfect replacement, so use that one. --- demos/gtk-demo/clipboard.c | 46 +++++++-------- demos/gtk-demo/cursors.ui | 72 ++++++++++++------------ demos/gtk-demo/main.c | 2 +- gtk/gtkaboutdialog.c | 2 +- gtk/gtkbuilder.c | 5 +- gtk/gtkdnd.c | 2 +- gtk/gtkheaderbar.c | 3 +- gtk/gtkimage.c | 111 ++----------------------------------- gtk/gtkimage.h | 7 --- gtk/inspector/recorder.c | 2 +- tests/showrendernode.c | 2 +- tests/testclipboard2.c | 2 +- tests/testdnd2.c | 40 ++++++------- tests/testimage.c | 18 +++--- 14 files changed, 106 insertions(+), 208 deletions(-) diff --git a/demos/gtk-demo/clipboard.c b/demos/gtk-demo/clipboard.c index 5196b316fe..73a8d4ed6f 100644 --- a/demos/gtk-demo/clipboard.c +++ b/demos/gtk-demo/clipboard.c @@ -93,8 +93,8 @@ paste_button_clicked (GtkWidget *button, gdk_clipboard_read_text_async (clipboard, NULL, paste_received, entry); } -static GdkTexture * -get_image_texture (GtkImage *image) +static GdkPaintable * +get_image_paintable (GtkImage *image) { const gchar *icon_name; GtkIconTheme *icon_theme; @@ -102,15 +102,15 @@ get_image_texture (GtkImage *image) switch (gtk_image_get_storage_type (image)) { - case GTK_IMAGE_TEXTURE: - return g_object_ref (gtk_image_get_texture (image)); + case GTK_IMAGE_PAINTABLE: + return g_object_ref (gtk_image_get_paintable (image)); case GTK_IMAGE_ICON_NAME: icon_name = gtk_image_get_icon_name (image); icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (image))); icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, 48, GTK_ICON_LOOKUP_GENERIC_FALLBACK); if (icon_info == NULL) return NULL; - return gtk_icon_info_load_texture (icon_info); + return GDK_PAINTABLE (gtk_icon_info_load_texture (icon_info)); default: g_warning ("Image storage type %d not handled", gtk_image_get_storage_type (image)); @@ -123,13 +123,13 @@ drag_begin (GtkWidget *widget, GdkDragContext *context, gpointer data) { - GdkTexture *texture; + GdkPaintable *paintable; - texture = get_image_texture (GTK_IMAGE (widget)); - if (texture) + paintable = get_image_paintable (GTK_IMAGE (widget)); + if (paintable) { - gtk_drag_set_icon_paintable (context, GDK_PAINTABLE (texture), -2, -2); - g_object_unref (texture); + gtk_drag_set_icon_paintable (context, paintable, -2, -2); + g_object_unref (paintable); } } @@ -141,11 +141,11 @@ drag_data_get (GtkWidget *widget, guint time, gpointer data) { - GdkTexture *texture; + GdkPaintable *paintable; - texture = get_image_texture (GTK_IMAGE (widget)); - if (texture) - gtk_selection_data_set_texture (selection_data, texture); + paintable = get_image_paintable (GTK_IMAGE (widget)); + if (GDK_IS_TEXTURE (paintable)) + gtk_selection_data_set_texture (selection_data, GDK_TEXTURE (paintable)); } static void @@ -160,7 +160,7 @@ drag_data_received (GtkWidget *widget, GdkTexture *texture; texture = gtk_selection_data_get_texture (selection_data); - gtk_image_set_from_texture (GTK_IMAGE (data), texture); + gtk_image_set_from_paintable (GTK_IMAGE (data), GDK_PAINTABLE (texture)); g_object_unref (texture); } } @@ -170,16 +170,16 @@ copy_image (GtkMenuItem *item, gpointer data) { GdkClipboard *clipboard; - GdkTexture *texture; + GdkPaintable *paintable; clipboard = gtk_widget_get_clipboard (GTK_WIDGET (data)); - texture = get_image_texture (GTK_IMAGE (data)); + paintable = get_image_paintable (GTK_IMAGE (data)); - if (texture) - { - gdk_clipboard_set_texture (clipboard, texture); - g_object_unref (texture); - } + if (GDK_IS_TEXTURE (paintable)) + gdk_clipboard_set_texture (clipboard, GDK_TEXTURE (paintable)); + + if (paintable) + g_object_unref (paintable); } static void @@ -193,7 +193,7 @@ paste_image_received (GObject *source, if (texture == NULL) return; - gtk_image_set_from_texture (GTK_IMAGE (data), texture); + gtk_image_set_from_paintable (GTK_IMAGE (data), GDK_PAINTABLE (texture)); g_object_unref (texture); } diff --git a/demos/gtk-demo/cursors.ui b/demos/gtk-demo/cursors.ui index 9a78fa436f..8077c4c4c3 100644 --- a/demos/gtk-demo/cursors.ui +++ b/demos/gtk-demo/cursors.ui @@ -677,7 +677,7 @@ 10 - resource:///cursors/default_cursor.png + resource:///cursors/default_cursor.png @@ -734,7 +734,7 @@ 10 - resource:///cursors/none_cursor.png + resource:///cursors/none_cursor.png @@ -791,7 +791,7 @@ 10 - resource:///cursors/gtk_logo_cursor.png + resource:///cursors/gtk_logo_cursor.png @@ -861,7 +861,7 @@ 10 - resource:///cursors/context_menu_cursor.png + resource:///cursors/context_menu_cursor.png @@ -918,7 +918,7 @@ 10 - resource:///cursors/help_cursor.png + resource:///cursors/help_cursor.png @@ -975,7 +975,7 @@ 10 - resource:///cursors/pointer_cursor.png + resource:///cursors/pointer_cursor.png @@ -1032,7 +1032,7 @@ 10 - resource:///cursors/progress_cursor.png + resource:///cursors/progress_cursor.png @@ -1089,7 +1089,7 @@ 10 - resource:///cursors/wait_cursor.png + resource:///cursors/wait_cursor.png @@ -1159,7 +1159,7 @@ 10 - resource:///cursors/cell_cursor.png + resource:///cursors/cell_cursor.png @@ -1216,7 +1216,7 @@ 10 - resource:///cursors/crosshair_cursor.png + resource:///cursors/crosshair_cursor.png @@ -1273,7 +1273,7 @@ 10 - resource:///cursors/text_cursor.png + resource:///cursors/text_cursor.png @@ -1330,7 +1330,7 @@ 10 - resource:///cursors/vertical_text_cursor.png + resource:///cursors/vertical_text_cursor.png @@ -1400,7 +1400,7 @@ 10 - resource:///cursors/alias_cursor.png + resource:///cursors/alias_cursor.png @@ -1457,7 +1457,7 @@ 10 - resource:///cursors/copy_cursor.png + resource:///cursors/copy_cursor.png @@ -1514,7 +1514,7 @@ 10 - resource:///cursors/move_cursor.png + resource:///cursors/move_cursor.png @@ -1571,7 +1571,7 @@ 10 - resource:///cursors/no_drop_cursor.png + resource:///cursors/no_drop_cursor.png @@ -1628,7 +1628,7 @@ 10 - resource:///cursors/not_allowed_cursor.png + resource:///cursors/not_allowed_cursor.png @@ -1685,7 +1685,7 @@ 10 - resource:///cursors/grab_cursor.png + resource:///cursors/grab_cursor.png @@ -1742,7 +1742,7 @@ 10 - resource:///cursors/grabbing_cursor.png + resource:///cursors/grabbing_cursor.png @@ -1812,7 +1812,7 @@ 10 - resource:///cursors/all_scroll_cursor.png + resource:///cursors/all_scroll_cursor.png @@ -1869,7 +1869,7 @@ 10 - resource:///cursors/col_resize_cursor.png + resource:///cursors/col_resize_cursor.png @@ -1926,7 +1926,7 @@ 10 - resource:///cursors/row_resize_cursor.png + resource:///cursors/row_resize_cursor.png @@ -1983,7 +1983,7 @@ 10 - resource:///cursors/n_resize_cursor.png + resource:///cursors/n_resize_cursor.png @@ -2040,7 +2040,7 @@ 10 - resource:///cursors/e_resize_cursor.png + resource:///cursors/e_resize_cursor.png @@ -2097,7 +2097,7 @@ 10 - resource:///cursors/s_resize_cursor.png + resource:///cursors/s_resize_cursor.png @@ -2154,7 +2154,7 @@ 10 - resource:///cursors/w_resize_cursor.png + resource:///cursors/w_resize_cursor.png @@ -2211,7 +2211,7 @@ 10 - resource:///cursors/ne_resize_cursor.png + resource:///cursors/ne_resize_cursor.png @@ -2268,7 +2268,7 @@ 10 - resource:///cursors/nw_resize_cursor.png + resource:///cursors/nw_resize_cursor.png @@ -2325,7 +2325,7 @@ 10 - resource:///cursors/sw_resize_cursor.png + resource:///cursors/sw_resize_cursor.png @@ -2382,7 +2382,7 @@ 10 - resource:///cursors/se_resize_cursor.png + resource:///cursors/se_resize_cursor.png @@ -2439,7 +2439,7 @@ 10 - resource:///cursors/ew_resize_cursor.png + resource:///cursors/ew_resize_cursor.png @@ -2496,7 +2496,7 @@ 10 - resource:///cursors/ns_resize_cursor.png + resource:///cursors/ns_resize_cursor.png @@ -2553,7 +2553,7 @@ 10 - resource:///cursors/nesw_resize_cursor.png + resource:///cursors/nesw_resize_cursor.png @@ -2610,7 +2610,7 @@ 10 - resource:///cursors/nwse_resize_cursor.png + resource:///cursors/nwse_resize_cursor.png @@ -2680,7 +2680,7 @@ 10 - resource:///cursors/zoom_in_cursor.png + resource:///cursors/zoom_in_cursor.png @@ -2737,7 +2737,7 @@ 10 - resource:///cursors/zoom_out_cursor.png + resource:///cursors/zoom_out_cursor.png diff --git a/demos/gtk-demo/main.c b/demos/gtk-demo/main.c index 95798c7c2f..bf009ab46f 100644 --- a/demos/gtk-demo/main.c +++ b/demos/gtk-demo/main.c @@ -555,7 +555,7 @@ add_data_tab (const gchar *demoname) resource_name = g_strconcat (resource_dir, "/", resources[i], NULL); widget = gtk_image_new_from_resource (resource_name); - if (gtk_image_get_texture (GTK_IMAGE (widget)) == NULL) + if (gtk_image_get_paintable (GTK_IMAGE (widget)) == NULL) { GBytes *bytes; diff --git a/gtk/gtkaboutdialog.c b/gtk/gtkaboutdialog.c index 03a17325b7..03e7208713 100644 --- a/gtk/gtkaboutdialog.c +++ b/gtk/gtkaboutdialog.c @@ -1878,7 +1878,7 @@ gtk_about_dialog_set_logo_icon_name (GtkAboutDialog *about, } else if ((icons = gtk_window_get_default_icon_list ())) { - gtk_image_set_from_texture (GTK_IMAGE (priv->logo_image), icons->data); + gtk_image_set_from_paintable (GTK_IMAGE (priv->logo_image), icons->data); g_list_free (icons); } else diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c index c492da1e4e..98bde12161 100644 --- a/gtk/gtkbuilder.c +++ b/gtk/gtkbuilder.c @@ -529,6 +529,7 @@ gtk_builder_get_parameters (GtkBuilder *builder, if (G_IS_PARAM_SPEC_OBJECT (prop->pspec) && (G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != GDK_TYPE_PIXBUF) && (G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != GDK_TYPE_TEXTURE) && + (G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != GDK_TYPE_PAINTABLE) && (G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != G_TYPE_FILE)) { GObject *object = g_hash_table_lookup (builder->priv->objects, @@ -2050,6 +2051,7 @@ gtk_builder_value_from_string_type (GtkBuilder *builder, case G_TYPE_OBJECT: case G_TYPE_INTERFACE: if (G_VALUE_HOLDS (value, GDK_TYPE_PIXBUF) || + G_VALUE_HOLDS (value, GDK_TYPE_PAINTABLE) || G_VALUE_HOLDS (value, GDK_TYPE_TEXTURE)) { gchar *filename; @@ -2102,7 +2104,8 @@ gtk_builder_value_from_string_type (GtkBuilder *builder, if (pixbuf) { - if (G_VALUE_HOLDS (value, GDK_TYPE_TEXTURE)) + if (G_VALUE_HOLDS (value, GDK_TYPE_TEXTURE) || + G_VALUE_HOLDS (value, GDK_TYPE_PAINTABLE)) { GdkTexture *texture = gdk_texture_new_for_pixbuf (pixbuf); g_value_set_object (value, texture); diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c index 3eb081687b..ffaf0847ff 100644 --- a/gtk/gtkdnd.c +++ b/gtk/gtkdnd.c @@ -1205,7 +1205,7 @@ gtk_drag_set_icon_surface (GdkDragContext *context, cairo_surface_set_device_offset (surface, 0, 0); texture = gdk_texture_new_for_surface (surface); - widget = gtk_image_new_from_texture (texture); + widget = gtk_image_new_from_paintable (GDK_PAINTABLE (texture)); g_object_unref (texture); gtk_drag_set_icon_widget_internal (context, widget, (int)hot_x, (int)hot_y, TRUE); diff --git a/gtk/gtkheaderbar.c b/gtk/gtkheaderbar.c index 0a67447961..a919fc8235 100644 --- a/gtk/gtkheaderbar.c +++ b/gtk/gtkheaderbar.c @@ -228,7 +228,8 @@ _gtk_header_bar_update_window_icon (GtkHeaderBar *bar, if (texture) { - gtk_image_set_from_texture (GTK_IMAGE (priv->titlebar_icon), texture); + gtk_image_set_from_paintable (GTK_IMAGE (priv->titlebar_icon), + GDK_PAINTABLE (texture)); g_object_unref (texture); gtk_widget_show (priv->titlebar_icon); diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c index 8a8a8235f5..f56ea2b1e0 100644 --- a/gtk/gtkimage.c +++ b/gtk/gtkimage.c @@ -62,7 +62,7 @@ * If you want to handle errors in loading the file yourself, * for example by displaying an error message, then load the image with * gdk_texture_new_from_file(), then create the #GtkImage with - * gtk_image_new_from_texture(). + * gtk_image_new_from_paintable(). * * Sometimes an application will want to avoid depending on external data * files, such as image files. See the documentation of #GResource for details. @@ -123,7 +123,6 @@ enum { PROP_0, PROP_PAINTABLE, - PROP_TEXTURE, PROP_FILE, PROP_ICON_SIZE, PROP_PIXEL_SIZE, @@ -167,13 +166,6 @@ gtk_image_class_init (GtkImageClass *class) GDK_TYPE_PAINTABLE, GTK_PARAM_READWRITE); - image_props[PROP_TEXTURE] = - g_param_spec_object ("texture", - P_("Texture"), - P_("A GdkTexture to display"), - GDK_TYPE_TEXTURE, - GTK_PARAM_READWRITE); - image_props[PROP_FILE] = g_param_spec_string ("file", P_("Filename"), @@ -340,9 +332,6 @@ gtk_image_set_property (GObject *object, case PROP_PAINTABLE: gtk_image_set_from_paintable (image, g_value_get_object (value)); break; - case PROP_TEXTURE: - gtk_image_set_from_texture (image, g_value_get_object (value)); - break; case PROP_FILE: gtk_image_set_from_file (image, g_value_get_string (value)); break; @@ -395,9 +384,6 @@ gtk_image_get_property (GObject *object, case PROP_PAINTABLE: g_value_set_object (value, _gtk_icon_helper_peek_paintable (priv->icon_helper)); break; - case PROP_TEXTURE: - g_value_set_object (value, _gtk_icon_helper_peek_texture (priv->icon_helper)); - break; case PROP_FILE: g_value_set_string (value, priv->filename); break; @@ -553,33 +539,6 @@ gtk_image_new_from_paintable (GdkPaintable *paintable) return GTK_WIDGET (image); } -/** - * gtk_image_new_from_texture: - * @texture: (allow-none): a #GdkTexture, or %NULL - * - * Creates a new #GtkImage displaying @texture. - * The #GtkImage does not assume a reference to the - * texture; you still need to unref it if you own references. - * #GtkImage will add its own reference rather than adopting yours. - * - * Note that this function just creates an #GtkImage from the texture. The - * #GtkImage created will not react to state changes. Should you want that, - * you should use gtk_image_new_from_icon_name(). - * - * Returns: a new #GtkImage - **/ -GtkWidget* -gtk_image_new_from_texture (GdkTexture *texture) -{ - GtkImage *image; - - image = g_object_new (GTK_TYPE_IMAGE, NULL); - - gtk_image_set_from_texture (image, texture); - - return GTK_WIDGET (image); -} - /** * gtk_image_new_from_icon_name: * @icon_name: (nullable): an icon name or %NULL @@ -878,9 +837,8 @@ gtk_image_set_from_resource (GtkImage *image, * * See gtk_image_new_from_pixbuf() for details. * - * Note: This is a helper for gtk_image_set_from_texture(), and you can't - * get back the exact pixbuf once this is called, only a texture. - * + * Note: This is a helper for gtk_image_set_from_paintable(), and you can't + * get back the exact pixbuf once this is called, only a paintable. **/ void gtk_image_set_from_pixbuf (GtkImage *image, @@ -896,7 +854,7 @@ gtk_image_set_from_pixbuf (GtkImage *image, else texture = NULL; - gtk_image_set_from_texture (image, texture); + gtk_image_set_from_paintable (image, GDK_PAINTABLE (texture)); if (texture) g_object_unref (texture); @@ -1028,40 +986,6 @@ gtk_image_set_from_paintable (GtkImage *image, g_object_thaw_notify (G_OBJECT (image)); } -/** - * gtk_image_set_from_texture: - * @image: a #GtkImage - * @texture: (nullable): a #GdkTexture or %NULL - * - * See gtk_image_new_from_texture() for details. - **/ -void -gtk_image_set_from_texture (GtkImage *image, - GdkTexture *texture) -{ - GtkImagePrivate *priv = gtk_image_get_instance_private (image); - - g_return_if_fail (GTK_IS_IMAGE (image)); - g_return_if_fail (texture == NULL || GDK_IS_TEXTURE (texture)); - - g_object_freeze_notify (G_OBJECT (image)); - - if (texture) - g_object_ref (texture); - - gtk_image_clear (image); - - if (texture) - { - _gtk_icon_helper_set_texture (priv->icon_helper, texture); - g_object_unref (texture); - } - - g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_TEXTURE]); - - g_object_thaw_notify (G_OBJECT (image)); -} - /** * gtk_image_get_storage_type: * @image: a #GtkImage @@ -1105,29 +1029,6 @@ gtk_image_get_paintable (GtkImage *image) return _gtk_icon_helper_peek_paintable (priv->icon_helper); } -/** - * gtk_image_get_texture: - * @image: a #GtkImage - * - * Gets the image #GdkTexture being displayed by the #GtkImage. - * The storage type of the image must be %GTK_IMAGE_EMPTY or - * %GTK_IMAGE_TEXTURE (see gtk_image_get_storage_type()). - * The caller of this function does not own a reference to the - * returned texture. - * - * Returns: (nullable) (transfer none): the displayed texture, or %NULL if - * the image is empty - **/ -GdkTexture * -gtk_image_get_texture (GtkImage *image) -{ - GtkImagePrivate *priv = gtk_image_get_instance_private (image); - - g_return_val_if_fail (GTK_IS_IMAGE (image), NULL); - - return _gtk_icon_helper_peek_texture (priv->icon_helper); -} - /** * gtk_image_get_icon_name: * @image: a #GtkImage @@ -1301,12 +1202,10 @@ gtk_image_notify_for_storage_type (GtkImage *image, case GTK_IMAGE_GICON: g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_GICON]); break; - case GTK_IMAGE_TEXTURE: - g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_TEXTURE]); - break; case GTK_IMAGE_PAINTABLE: g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_PAINTABLE]); break; + case GTK_IMAGE_TEXTURE: case GTK_IMAGE_EMPTY: default: break; diff --git a/gtk/gtkimage.h b/gtk/gtkimage.h index 6d5a8309b0..f6f3db12a0 100644 --- a/gtk/gtkimage.h +++ b/gtk/gtkimage.h @@ -111,8 +111,6 @@ GtkWidget* gtk_image_new_from_resource (const gchar *resource_path); GDK_AVAILABLE_IN_ALL GtkWidget* gtk_image_new_from_pixbuf (GdkPixbuf *pixbuf); GDK_AVAILABLE_IN_ALL -GtkWidget* gtk_image_new_from_texture (GdkTexture *texture); -GDK_AVAILABLE_IN_ALL GtkWidget* gtk_image_new_from_paintable (GdkPaintable *paintable); GDK_AVAILABLE_IN_ALL GtkWidget* gtk_image_new_from_icon_name (const gchar *icon_name); @@ -131,9 +129,6 @@ GDK_AVAILABLE_IN_ALL void gtk_image_set_from_pixbuf (GtkImage *image, GdkPixbuf *pixbuf); GDK_AVAILABLE_IN_ALL -void gtk_image_set_from_texture (GtkImage *image, - GdkTexture *texture); -GDK_AVAILABLE_IN_ALL void gtk_image_set_from_paintable (GtkImage *image, GdkPaintable *paintable); GDK_AVAILABLE_IN_ALL @@ -158,8 +153,6 @@ void gtk_image_set_can_shrink (GtkImage *image, GDK_AVAILABLE_IN_ALL GtkImageType gtk_image_get_storage_type (GtkImage *image); -GDK_AVAILABLE_IN_ALL -GdkTexture *gtk_image_get_texture (GtkImage *image); GDK_AVAILABLE_IN_ALL GdkPaintable *gtk_image_get_paintable (GtkImage *image); diff --git a/gtk/inspector/recorder.c b/gtk/inspector/recorder.c index f55c2cd6a2..9ea5ff93a2 100644 --- a/gtk/inspector/recorder.c +++ b/gtk/inspector/recorder.c @@ -884,7 +884,7 @@ node_property_activated (GtkTreeView *tv, popover = gtk_popover_new (GTK_WIDGET (tv)); gtk_popover_set_pointing_to (GTK_POPOVER (popover), &rect); - image = gtk_image_new_from_texture (texture); + image = gtk_image_new_from_paintable (GDK_PAINTABLE (texture)); g_object_set (image, "margin", 20, NULL); gtk_container_add (GTK_CONTAINER (popover), image); gtk_popover_popup (GTK_POPOVER (popover)); diff --git a/tests/showrendernode.c b/tests/showrendernode.c index 298e0ec866..d4de840c50 100644 --- a/tests/showrendernode.c +++ b/tests/showrendernode.c @@ -197,7 +197,7 @@ main (int argc, char **argv) GdkWindow *gdk_window = gdk_window_new_toplevel (gdk_display_get_default(), 10 , 10); GskRenderer *renderer = gsk_renderer_new_for_window (gdk_window); GdkTexture *texture = gsk_renderer_render_texture (renderer, GTK_NODE_VIEW (nodeview)->node, NULL); - GtkWidget *image = gtk_image_new_from_texture (texture); + GtkWidget *image = gtk_image_new_from_paintable (GDK_PAINTABLE (texture)); gtk_container_add (GTK_CONTAINER (box), nodeview); gtk_container_add (GTK_CONTAINER (box), image); diff --git a/tests/testclipboard2.c b/tests/testclipboard2.c index 5bbe112183..86c0e5dc3f 100644 --- a/tests/testclipboard2.c +++ b/tests/testclipboard2.c @@ -48,7 +48,7 @@ texture_loaded_cb (GObject *clipboard, return; } - gtk_image_set_from_texture (data, texture); + gtk_image_set_from_paintable (data, GDK_PAINTABLE (texture)); g_object_unref (texture); } diff --git a/tests/testdnd2.c b/tests/testdnd2.c index 7fee35c7cc..f3916d4ee9 100644 --- a/tests/testdnd2.c +++ b/tests/testdnd2.c @@ -1,13 +1,13 @@ #include -static GdkTexture * -get_image_texture (GtkImage *image, - int *out_size) +static GdkPaintable * +get_image_paintable (GtkImage *image, + int *out_size) { GtkIconTheme *icon_theme; const char *icon_name; int width = 48; - GdkTexture *texture; + GdkPaintable *paintable; GtkIconInfo *icon_info; switch (gtk_image_get_storage_type (image)) @@ -21,9 +21,9 @@ get_image_texture (GtkImage *image, icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (image))); *out_size = width; icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, width, GTK_ICON_LOOKUP_GENERIC_FALLBACK); - texture = gtk_icon_info_load_texture (icon_info); + paintable = GDK_PAINTABLE (gtk_icon_info_load_texture (icon_info)); g_object_unref (icon_info); - return texture; + return paintable; default: g_warning ("Image storage type %d not handled", gtk_image_get_storage_type (image)); @@ -42,12 +42,12 @@ image_drag_begin (GtkWidget *widget, GdkDragContext *context, gpointer data) { - GdkTexture *texture; + GdkPaintable *paintable; gint hotspot; gint hot_x, hot_y; gint size; - texture = get_image_texture (GTK_IMAGE (data), &size); + paintable = get_image_paintable (GTK_IMAGE (data), &size); hotspot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (data), "hotspot")); switch (hotspot) { @@ -65,8 +65,8 @@ image_drag_begin (GtkWidget *widget, hot_y = size; break; } - gtk_drag_set_icon_paintable (context, GDK_PAINTABLE (texture), hot_x, hot_y); - g_object_unref (texture); + gtk_drag_set_icon_paintable (context, paintable, hot_x, hot_y); + g_object_unref (paintable); } static void @@ -93,7 +93,7 @@ window_drag_begin (GtkWidget *widget, GdkDragContext *context, gpointer data) { - GdkTexture *texture; + GdkPaintable *paintable; GtkWidget *image; int hotspot; int size; @@ -104,9 +104,9 @@ window_drag_begin (GtkWidget *widget, if (image == NULL) { g_print ("creating new drag widget\n"); - texture = get_image_texture (GTK_IMAGE (data), &size); - image = gtk_image_new_from_texture (texture); - g_object_unref (texture); + paintable = get_image_paintable (GTK_IMAGE (data), &size); + image = gtk_image_new_from_paintable (paintable); + g_object_unref (paintable); g_object_ref (image); g_object_set_data (G_OBJECT (widget), "drag widget", image); g_signal_connect (image, "destroy", G_CALLBACK (drag_widget_destroyed), widget); @@ -158,15 +158,17 @@ image_drag_data_get (GtkWidget *widget, guint time, gpointer data) { - GdkTexture *texture; + GdkPaintable *paintable; const gchar *name; int size; if (gtk_selection_data_targets_include_image (selection_data, TRUE)) { - texture = get_image_texture (GTK_IMAGE (data), &size); - gtk_selection_data_set_texture (selection_data, texture); - g_object_unref (texture); + paintable = get_image_paintable (GTK_IMAGE (data), &size); + if (GDK_IS_TEXTURE (paintable)) + gtk_selection_data_set_texture (selection_data, GDK_TEXTURE (paintable)); + if (paintable) + g_object_unref (paintable); } else if (gtk_selection_data_targets_include_text (selection_data)) { @@ -199,7 +201,7 @@ image_drag_data_received (GtkWidget *widget, GdkTexture *texture; texture = gtk_selection_data_get_texture (selection_data); - gtk_image_set_from_texture (GTK_IMAGE (data), texture); + gtk_image_set_from_paintable (GTK_IMAGE (data), GDK_PAINTABLE (texture)); g_object_unref (texture); } diff --git a/tests/testimage.c b/tests/testimage.c index ffe3b69ee7..2b222f9547 100644 --- a/tests/testimage.c +++ b/tests/testimage.c @@ -24,10 +24,10 @@ drag_begin (GtkWidget *widget, gpointer data) { GtkWidget *image = GTK_WIDGET (data); - GdkTexture *texture; + GdkPaintable *paintable; - texture = gtk_image_get_texture (GTK_IMAGE (image)); - gtk_drag_set_icon_paintable (context, GDK_PAINTABLE (texture), -2, -2); + paintable = gtk_image_get_paintable (GTK_IMAGE (image)); + gtk_drag_set_icon_paintable (context, paintable, -2, -2); } void @@ -38,11 +38,11 @@ drag_data_get (GtkWidget *widget, gpointer data) { GtkWidget *image = GTK_WIDGET (data); - GdkTexture *texture; + GdkPaintable *paintable; - texture = gtk_image_get_texture (GTK_IMAGE (image)); - gtk_selection_data_set_texture (selection_data, texture); - g_object_unref (texture); + paintable = gtk_image_get_paintable (GTK_IMAGE (image)); + if (GDK_IS_TEXTURE (paintable)) + gtk_selection_data_set_texture (selection_data, GDK_TEXTURE (paintable)); } static void @@ -60,7 +60,7 @@ drag_data_received (GtkWidget *widget, return; texture = gtk_selection_data_get_texture (selection_data); - gtk_image_set_from_texture (GTK_IMAGE (image), texture); + gtk_image_set_from_paintable (GTK_IMAGE (image), GDK_PAINTABLE (texture)); g_object_unref (texture); } @@ -113,7 +113,7 @@ main (int argc, char **argv) icon_info = gtk_icon_theme_lookup_icon_for_scale (theme, icon_name, 48, gtk_widget_get_scale_factor (window), GTK_ICON_LOOKUP_GENERIC_FALLBACK); texture = gtk_icon_info_load_texture (icon_info); g_object_unref (icon_info); - image = gtk_image_new_from_texture (texture); + image = gtk_image_new_from_paintable (GDK_PAINTABLE (texture)); g_object_unref (texture); gtk_grid_attach (GTK_GRID (grid), image, 2, 1, 1, 1); -- 2.30.2